package org.example.springchatroom.controller;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.example.springchatroom.constants.Constants;
import org.example.springchatroom.mapper.FriendMapper;
import org.example.springchatroom.model.Friend;
import org.example.springchatroom.model.Result;
import org.example.springchatroom.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/6
 * Time: 15:42
 */
@RestController
@RequestMapping("/friend")
@Slf4j
public class FriendController {
    @Autowired
    private FriendMapper friendMapper;

    @RequestMapping(value ="/getFriendList",method = RequestMethod.GET)
    public Result<List<Friend>> getFriendList(HttpServletRequest request) {
        String token = request.getHeader(Constants.REQUEST_HEADER_TOKEN);
        log.info("getFriendList接收token,token:{}", token);
        Integer userId = JwtUtils.getIdByToken(token);
        log.info("getFriendList解析token,userId:{}", userId);
        return Result.success(friendMapper.selectByUserId(userId));
    }
}
